
package com.huizhan.web.dao;

import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import com.huizhan.web.model.*;


@Repository 
public interface AccountDao extends JpaRepository<Account,String>
{
    /**
     * 根据手机号码密码获取用户
     * @param phone 手机号码
     * @param password 密码
     * @return 用户信息
     */
    Account findByPhoneAndPassword(String phone, String password);

    /**
     * 根据手机号码获取用户
     * @param phone 手机号码
     * @return 用户信息
     */
    Account findByPhone(String phone);

    /**
     * 分页查询用户集合
     * @param name 姓名
     * @param phone 手机号
     * @param pageable 分页参数
     * @return 用户集合
     */
    @Query(
        value = "SELECT * FROM account"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (phone LIKE CONCAT('%',?2,'%') OR ?2  = '' )",
        countQuery = "SELECT COUNT(1) FROM account"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '' )"
            + " AND (phone LIKE CONCAT('%',?2,'%') OR ?2  = '' )",
        nativeQuery = true
    )
    Page<Account> findByWhere(String name,String phone, Pageable  pageable);
    
    
}
